//
//  XJTabBarController.m
//  s.
//
//  Created by pro on 2021/1/17.
//  Copyright © 2021 hailuo. All rights reserved.
//

#import "XJTabBarController.h"
#import "MeViewController.h"
#import "HomeViewController.h"
#import "SportViewController.h"

//MARK: - ******************** HLTabBar ********************

@interface HLTabBar : UITabBar

@end

@implementation HLTabBar

//- (void)layoutSubviews
//{
//    [super layoutSubviews];
//    for (UIButton *aBtn in self.subviews) {
//        if ([aBtn isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
//
//            CGRect frame = aBtn.frame;
//            frame.origin.y -= 6; // 顶部上移6
//            aBtn.frame = frame;
//
//            // 设置 _imageInsets.bottom 达到缩短图片文字间距
//            if ([aBtn valueForKey:@"_imageInsets"]) {
//                [aBtn setValue:[NSValue valueWithUIEdgeInsets:UIEdgeInsetsMake(0, 0, -7, 0)] forKey:@"_imageInsets"];
//            }
//
//        }
//    }
//}
- (instancetype)init
{
    if (self = [super init]) {
        
        self.backgroundColor = [UIColor clearColor];
        self.tintColor = JYColor_Main();
        
        //去除tabBar上方线条
//        [self setBackgroundImage:[UIImage new]];
//        [self setShadowImage:[UIImage new]];
//        if (@available(iOS 13.0, *)){
//            UITabBarAppearance* tabBarAppearance = [[UITabBarAppearance alloc] init];
//            tabBarAppearance.shadowColor = [UIColor clearColor];
//            [self setStandardAppearance:tabBarAppearance];
//        }
        
        // 顶部横线
//        UIView *topLine = [UIView new];
//        topLine.backgroundColor = [jy_HexColor(@"#000000") colorWithAlphaComponent:0.08];
//        [self addSubview:topLine];
//        [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
//            kMakeLV(0);
//            kMakeRV(0);
//            kMakeTV(0);
//            kMakeHV(1);
//        }];
    }
    return self;
}

//- (void)drawRect:(CGRect)rect {
//    [super drawRect:rect];
//    
//    [[UIColor whiteColor] set];
//
//    
//    UIBezierPath *path = [[UIBezierPath alloc] init];
//    [path moveToPoint:CGPointMake(0, self.height)];
//
//      // 添加子路径
//    [path addLineToPoint:CGPointMake(0, self.height - 20)];//添加一条子路径
//    
//    [path addArcWithCenter:CGPointMake(20, 20) radius:20 startAngle:M_PI endAngle:-M_PI_2 clockwise:YES];
//
//    [path addLineToPoint:CGPointMake(self.width / 2 - 40, 0)];//添加一条子路径
//
//    [path addArcWithCenter:CGPointMake(self.width / 2 , 0) radius:40 startAngle:M_PI endAngle:0 clockwise:NO];
//
//    [path addLineToPoint:CGPointMake(self.width - 20, 0)];//添加一条子路径
//
//    [path addArcWithCenter:CGPointMake(self.width - 20,  20) radius:20 startAngle:-M_PI_2 endAngle:0 clockwise:YES];
//
//   
//    [path addLineToPoint:CGPointMake(self.width, self.height)];//添加一条子路径
//    [[UIColor whiteColor] setFill];
//    [path closePath];
//    
//    [path fillWithBlendMode:kCGBlendModeOverlay alpha:1];
//
//    
//    [path stroke];
//    self.layer.shadowColor = [UIColor blackColor].CGColor;
//    self.layer.shadowOpacity = 0.3;
//    self.layer.shadowOffset = CGSizeMake(0, -5);
//    self.layer.shadowPath = path.CGPath;
//}

@end

//MARK: - ******************** XJTabBarController ********************
@interface XJTabBarController ()<UITabBarControllerDelegate>

@end

@implementation XJTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = KLColor(@"#FFFFFF");
    self.delegate = self;
    
    
//    self.view.layer.shadowColor = [UIColor blackColor].CGColor;
//    self.view.layer.shadowOpacity = 0.3;
//    self.view.layer.shadowOffset = CGSizeMake(0, -5);
////    self.view.layer.shadowPath = path.CGPath;
//    self.view.layer.masksToBounds =  NO;
    
    NSDictionary *titleAttrs = [NSDictionary dictionaryWithObjectsAndKeys:KLColor(@"#666666"), NSForegroundColorAttributeName , U_font(12), NSFontAttributeName, nil];
    NSDictionary *titleSelAttrs = [NSDictionary dictionaryWithObjectsAndKeys:JYColor_Main(), NSForegroundColorAttributeName, U_font(12), NSFontAttributeName, nil];
    
    //     适配iOS13导致的bug
    if (@available(iOS 13.0, *)) {
        // iOS 13以上
        self.tabBar.tintColor = JYColor_Main();
        self.tabBar.unselectedItemTintColor = [UIColor lightGrayColor];
        UITabBarItem *item = [UITabBarItem appearance];
        [item setTitleTextAttributes:titleAttrs forState:UIControlStateNormal];
        [item setTitleTextAttributes:titleSelAttrs forState:UIControlStateSelected];
    } else {
        // iOS 13以下
        [[UITabBarItem appearance] setTitleTextAttributes:titleAttrs            forState:UIControlStateNormal];
        [[UITabBarItem appearance] setTitleTextAttributes:titleSelAttrs            forState:UIControlStateSelected];
    }
    
    [self setupChildViewControllers];
    // Do any additional setup after loading the view.
    
}


- (void)setupChildViewControllers {
    
    HomeViewController *homeVC = [[HomeViewController alloc] init];
    BENavigationController *homeNavi = [[BENavigationController alloc] initWithRootViewController:homeVC];
    homeNavi.tabBarItem.title = SWString(@"智能生活");
    homeNavi.tabBarItem.image = [UIImage imageNamed:@"bottom_smart_life_icon_u"];
    homeNavi.tabBarItem.selectedImage = [[UIImage imageNamed:@"bottom_smart_life_icon_n"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
   
    
   
    SportViewController *sportVC = [[SportViewController alloc] init];
    BENavigationController *sportNavi = [[BENavigationController alloc] initWithRootViewController:sportVC];
    sportNavi.tabBarItem.title = SWString(@"运动健康");
    sportNavi.tabBarItem.image = [UIImage imageNamed:@"bottom_sport_health_icon_u"];
    sportNavi.tabBarItem.selectedImage = [[UIImage imageNamed:@"bottom_sport_health_icon_n"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
   
    
   
  

    MeViewController *hallVC = [[MeViewController alloc] init];
    BENavigationController *hallNavi = [[BENavigationController alloc] initWithRootViewController:hallVC];
    hallNavi.tabBarItem.title = SWString(@"我的");
    hallNavi.tabBarItem.image = [UIImage imageNamed:@"bottom_me_icon_u"];
    hallNavi.tabBarItem.selectedImage = [[UIImage imageNamed:@"bottom_me_icon_n"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
   
    self.viewControllers = @[homeNavi , sportNavi,  hallNavi];
    
}


@end
